import { formInfoStore } from '@/store/modules/form';
import dictionary from './dictionary';

//vue3过滤器取消了
export const dictionaryFn = (state: any, val: any): any => {
  const formStore = formInfoStore();
  const dictionaryData = formStore.getDictionary;

  if (val && typeof val === 'object' && val.value !== undefined && val.text) {
    return val.text;
  }

  if (val !== 0 && !val && val != false) {
    return '';
  }

  if (dictionaryData[state.filterName]) {
    //本地数据字典
    if (val && typeof val === 'object' && val.value !== undefined) {
      return dictionaryData[state.filterName][typeof val === 'object' ? val.value : val];
    }
    if (val && Array.isArray(val)) {
      const arr = val.map((id) => dictionaryData[state.filterName][id]);
      return arr.join(',');
    } else {
      return dictionaryData[state.filterName][val];
    }
  } else if (dictionary[state.filterName]) {
    //本地数据字典
    if (typeof val === 'object' && val.value !== undefined) {
      return dictionary[state.filterName][typeof val === 'object' ? val.value : val];
    }
    if (val && Array.isArray(val)) {
      const arr = val.map((id) => dictionary[state.filterName][id]);
      return arr.join(',');
    } else {
      return dictionary[state.filterName][val];
    }
  }
};
export * from './time';
